package com.shine.commonlibrary.utils.base;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.shine.commonlibrary.BuildConfig;
import com.shine.commonlibrary.utils.utils.Utils;
import com.squareup.leakcanary.LeakCanary;

import jp.wasabeef.takt.Audience;
import jp.wasabeef.takt.Seat;
import jp.wasabeef.takt.Takt;

/**
 * Created by M_genius on 2017/9/6 14:33.
 * 描述：
 */

public class BaseApplication extends Application {

    private static BaseApplication baseApplication;

    @Override
    public void onCreate() {
        super.onCreate();
        baseApplication = this;

        //监测内存移除
        LeakCanary.install(this);

        //工具类初始化
        Utils.init(this);

        //UI卡顿检测，在右下角会显示当前页面的帧数情况
        if (BuildConfig.DEBUG) {
            Takt.stock(this)
                    .seat(Seat.BOTTOM_RIGHT)
                    .interval(250)
                    .color(Color.BLACK)
                    .size(20f)
                    .alpha(.5f)
                    .listener(new Audience() {
                        @Override
                        public void heartbeat(double fps) {
                            Log.d("Excellent!", fps + " fps");
                        }
                    }).play();
        }
    }

    public static Context getAppContext() {
        return baseApplication;
    }

    public static Resources getAppResources() {
        return baseApplication.getResources();
    }

    @Override
    public void onTerminate() {
        Takt.finish();
        super.onTerminate();
    }

    /**
     * 分包
     *
     * @param base
     */
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}
